<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Http\Repositories\CommentRepository;
use Illuminate\Http\Request;

class CommentController extends Controller
{
    protected $commentRepository;

    public function __construct(CommentRepository $commentRepository)
    {
        $this->commentRepository = $commentRepository;
    }

    /**
     * 评论列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(Request $request)
    {
        return responseResult($this->commentRepository->getList($request->all()), self::SUCCESS_CODE);
    }

    /**
     * 修改评论状态
     * @param $id
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function changeEnable($id, Request $request)
    {
        $this->validate($request, ['status' => 'required']);
        $result = $this->commentRepository->changeEnable($id, $request->get("status"));
        return responseResult([], $result ? self::SUCCESS_CODE : self::ERROR_CODE);
    }

    /**
     * 删除评论
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function del($id)
    {
        $result = $this->commentRepository->del($id);
        return responseResult([], $result ? self::SUCCESS_CODE : self::ERROR_CODE);
    }
}
